package battlecruiser.shooter;

import battlecruiser.board.ObserverBoard;
import battlecruiser.board.cell.coordinate.Coordinate;
import battlecruiser.shooter.reader.TargetReader;

import java.io.IOException;

/**
 * @author Yakiv Tymoshenko
 * @since 03.10.12
 */
public abstract class Shooter {

    protected ObserverBoard observerBoard;
    protected TargetReader targetReader;

    public DamageReport shoot() throws IOException {
        DamageReport result;
        Coordinate target;
        do {
            target = targetReader.readTarget();
            result = shoot(target);
            if(result == null) {
                break;
            }
        } while ((result.getShotResult() == ShotResult.HIT) && (target != null));
        return result;
    }

    public DamageReport shoot(Coordinate target) throws IOException {
        return observerBoard.getObservableBoard().processIncomingShot(target);
    }

    public void setTargetReader(TargetReader targetReader) {
        this.targetReader = targetReader;
    }
}
